install.packages("tidyverse")
library(ggplot2)
library(forcats)
library (dplyr)


##################################
##### DESCRIPTIVE STATISTICS #####
##################################

###############
## FIGURE 1A ##
###############

nsamean <- data.frame(lockdown=c("prelockdown [50]", "lockdown [50]", "postlockdown [50]"),
                violence=c(0.3775493, 0.1992587, 0.33971))


level_order <- c("prelockdown [50]", "lockdown [50]", "postlockdown [50]")

nonstate <- ggplot(nsamean, aes(x=factor(lockdown, level=level_order), y=violence, fill=lockdown)) +
 geom_bar(stat="identity") + 
 scale_fill_manual(values=c("#999999", "steelblue4", "steelblue4"))+
 ylab("mean number of nonstate actor \n violent events in state (daily)") + 
 scale_y_continuous(limits = c(0,0.5))+
 xlab("") + 
 theme_bw() +
 theme (axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 8),  axis.title.y = element_text(size = 14)) +
 theme(panel.grid.major=element_blank(), panel.grid.minor=element_blank(), legend.position = "none") 

print(nonstate)

###############
## FIGURE 1B ##
###############

samean <- data.frame(lockdown=c("prelockdown [50]", "lockdown [50]", "postlockdown [50]"),
                violence=c(0.1619357, 0.0805091, 0.1424027))


level_order <- c("prelockdown [50]", "lockdown [50]", "postlockdown [50]")

state <- ggplot(samean, aes(x=factor(lockdown, level=level_order), y=violence, fill=lockdown)) +
 geom_bar(stat="identity") + 
 scale_fill_manual(values=c("#999999", "#E69F00", "#E69F00"))+
 ylab("mean number of state actor \n violent events in state (daily)") + 
 scale_y_continuous(limits = c(0,0.5))+
 xlab("") + 
 theme_bw() +
 theme (axis.text.x = element_text(size = 14), axis.text.y = element_text(size = 8),  axis.title.y = element_text(size = 14)) +
 theme(panel.grid.major=element_blank(), panel.grid.minor=element_blank(), legend.position = "none") 

print(state)



######################################################
##########  Figure 2a - Baseline Plot ##############
######################################################

data <- data.frame(
Q=c("prelock", "lock", "postlock"),
margins = c(0.9915962, 0.8238999, 0.93272),
cimin = c(0.9897478, 0.8076069, 0.9165717),
cimax = c(0.9934447, 0.840193, 0.9488682)
) 

level_order <- c("prelock", "lock", "postlock")

D1 <- ggplot(data, aes(x = factor(Q, level = level_order), y=margins)) +
    scale_y_continuous(limits=c(0.50, 1.0))+
    annotate("text", x = 1, y=0.9915962, label = "0.992", vjust =
             2.25, size=4, fontface=3) +
    annotate("text", x = 2, y=0.8238999, label = "0.824", vjust =
    		 2.25, size=4, fontface=3) + 
    annotate("text", x = 3, y=0.93272, label = "0.933", vjust =
             2.25, size=4, fontface=3) +    
    	theme_bw() +
    	theme( 
    	axis.title.x=element_blank(),
    	axis.line = element_line(colour = "black"),
    	panel.grid.major = element_blank(), 
    	panel.grid.minor = element_blank(),
    	panel.border = element_blank(),
    	panel.background = element_blank()) +
    	theme(legend.position="None", legend.title=element_blank(), axis.text=element_text(size=12), legend.text=element_text(size=12), axis.title=element_text(size=12), legend.key.size = unit(1,"line")) 
 
D1<- D1 + scale_x_discrete(limits = c("prelockdown [50]","lockdown [50]\n(shortterm)", "postlockdown [50] \n(longterm)"))
D1<- D1 + labs(y="number of nonstate actor \n violent events (daily)")
 
 
#D1<- D1 + ggtitle(label = 'outcome: "number of daily events')

D1<- D1 + geom_point (x=1,y=0.999, size = 1)
D1<- D1 + geom_point (x=2,y=0.813, size = 1)
D1<- D1 + geom_point (x=3,y=0.934, size = 1)


D1<- D1 + geom_segment(aes(x=1.00, y=0.9897478, xend=1.00, yend=0.9934447, linetype=1, data = data) +
    scale_color_manual(values = c("grey30", "grey30"))
D1<- D1 + geom_segment(aes(x=0.75, y=0.9897478, xend=1.25, yend=0.9897478), linetype=1, data = data)
D1<- D1 + geom_segment(aes(x=0.75, y=0.9934447, xend=1.25, yend=0.9934447), linetype=1, data = data)

D1<- D1 + geom_segment(aes(x=2.00, y=0.8076069, xend=2.00, yend=0.840193, linetype=1, data = data)
D1<- D1 + geom_segment(aes(x=1.75, y=0.8076069, xend=2.25, yend=0.8076069), linetype=1, data = data)
D1<- D1 + geom_segment(aes(x=1.75, y=0.840193, xend=2.25, yend=0.840193), linetype=1, data = data)

D1<- D1 + geom_segment(aes(x=3.00, y=0.9165717, xend=3.00, yend=0.9488682), linetype=1, data = data) 
D1<- D1 + geom_segment(aes(x=2.75, y=0.9165717, xend=3.25, yend=0.9165717), linetype=1, data = data) 
D1<- D1 + geom_segment(aes(x=2.75, y=0.9488682, xend=3.25, yend=0.9488682), linetype=1, data = data)


D1<- D1 + geom_segment(aes(x=1.50, y=1.00, xend=1.50, yend=0.85), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=1.45, y=1.00, xend=1.55, yend=1.00), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=1.45, y=0.85, xend=1.55, yend=0.85), linetype="dotted", data = data) 


D1<- D1 + geom_point (x=1.50,y=.95, size = 1)
D1<- D1 + geom_label(
    label="17%", 
    x=1.50,
    y=.95,
    label.padding = unit(0.05, "lines"), # Rectangle size around label
    label.size = 0.15,
    color = "black",
    fill="#fff8dc"
  )

D1<- D1 + geom_segment(aes(x=2.50, y=1.00, xend=2.50, yend=0.95), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=2.45, y=1.00, xend=2.55, yend=1.00), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=2.45, y=0.95, xend=2.55, yend=0.95), linetype="dotted", data = data) 


D1<- D1 + geom_point (x=2.50,y=.98, size = 1)
D1<- D1 + geom_label(
    label="6%", 
    x=2.50,
    y=.98,
    label.padding = unit(0.05, "lines"), # Rectangle size around label
    label.size = 0.15,
    color = "black",
    fill="#fff8dc"
  )
print(D1)



######################################################
##########  Figure 2b - Baseline Plot ################
######################################################

data <- data.frame(
Q=c("prelock", "lock", "postlock"),
margins = c(1.006928, 0.66214531, 0.7515322),
cimin = c(1.002689, 0.6419419, 0.7273868),
cimax = c(1.011168, 0.6823487,  0.7756775)
) 
level_order <- c("prelock", "lock", "postlock")

D1 <- ggplot(data, aes(x = factor(Q, level = level_order), y=margins)) +
    scale_y_continuous(limits=c(0.50, 1.009))+
    annotate("text", x = 1, y=1.006928, label = "1.01", vjust =
             2.25, size=4, fontface=3) +
    annotate("text", x = 2, y=0.66214531, label = "0.662", vjust =
    		 2.25, size=4, fontface=3) + 
    annotate("text", x = 3, y=0.7515322, label = "0.752", vjust =
             2.25, size=4, fontface=3) +    
    	theme_bw() +
    	theme( 
    	axis.title.x=element_blank(),
    	axis.line = element_line(colour = "black"),
    	panel.grid.major = element_blank(), 
    	panel.grid.minor = element_blank(),
    	panel.border = element_blank(),
    	panel.background = element_blank()) +
    	theme(legend.position="None", legend.title=element_blank(), axis.text=element_text(size=12), legend.text=element_text(size=12), axis.title=element_text(size=12), legend.key.size = unit(1,"line")) 
 
D1<- D1 + scale_x_discrete(limits = c("prelockdown [50]","lockdown [50] \n(shortterm)", "postlockdown [50] \n(longterm)"))
D1<- D1 + labs(y="number of state actor \n violent events (daily)")
 
 
#D1<- D1 + ggtitle(label = 'outcome: "number of daily events')

D1<- D1 + geom_point (x=1,y=1.001, size = 1)
D1<- D1 + geom_point (x=2,y=0.662, size = 1)
D1<- D1 + geom_point (x=3,y=0.751, size = 1)

D1<- D1 + geom_segment(aes(x=1.00, y=1.002689, xend=1.00, yend=1.011168), linetype=1, data = data) +
    scale_color_manual(values = c("grey30", "grey30"))
D1<- D1 + geom_segment(aes(x=0.75, y=1.002689, xend=1.25, yend=1.002689), linetype=1, data = data)
D1<- D1 + geom_segment(aes(x=0.75, y=1.011168, xend=1.25, yend=1.011168), linetype=1, data = data)

D1<- D1 + geom_segment(aes(x=2.00, y=0.6419419, xend=2.00, yend=0.6823487), linetype=1, data = data)
D1<- D1 + geom_segment(aes(x=1.75, y=0.6419419, xend=2.25, yend=0.6419419), linetype=1, data = data)
D1<- D1 + geom_segment(aes(x=1.75, y=0.6823487, xend=2.25, yend=0.6823487), linetype=1, data = data)

D1<- D1 + geom_segment(aes(x=3.00, y=0.7273868, xend=3.00, yend=0.7756775), linetype=1, data = data) 
D1<- D1 + geom_segment(aes(x=2.75, y=0.7273868, xend=3.25, yend=0.7273868), linetype=1, data = data) 
D1<- D1 + geom_segment(aes(x=2.75, y=0.7756775, xend=3.25, yend=0.7756775), linetype=1, data = data)


D1<- D1 + geom_segment(aes(x=1.50, y=1.00, xend=1.50, yend=0.70), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=1.45, y=1.00, xend=1.55, yend=1.00), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=1.45, y=0.70, xend=1.55, yend=0.70), linetype="dotted", data = data) 

D1<- D1 + geom_point (x=1.50,y=.85, size = 1)
D1<- D1 + geom_label(
    label="34%", 
    x=1.50,
    y=.85,
    label.padding = unit(0.05, "lines"), # Rectangle size around label
    label.size = 0.15,
    color = "black",
    fill="#fff8dc"
  )

D1<- D1 + geom_segment(aes(x=2.50, y=1.00, xend=2.50, yend=0.80), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=2.45, y=1.00, xend=2.55, yend=1.00), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=2.45, y=0.80, xend=2.55, yend=0.80), linetype="dotted", data = data) 


D1<- D1 + geom_point (x=2.50,y=.95, size = 1)
D1<- D1 + geom_label(
    label="25%", 
    x=2.50,
    y=.95,
    label.padding = unit(0.05, "lines"), # Rectangle size around label
    label.size = 0.15,
    color = "black",
    fill="#fff8dc"
  )
print(D1)


##########################################################
#################  Figure 3a - lnGDP  #####################
##########################################################


data <- data.frame(
Q=c("prelock", "lock", "postlock"),
margins = c(11.0764, 11.05146, 11.15263),
cimin = c(11.07587, 11.05067, 11.15168),
cimax = c(11.07693, 11.05226, 11.15357)
) 
2
level_order <- c("prelock", "lock", "postlock")


D1 <- ggplot(data, aes(x = factor(Q, level = level_order), y=margins)) +
	scale_y_continuous(limits=c(11, 11.20))+
    annotate("text", x = 1, y=11.0764, label = "11.08", vjust =
             2.25, size=4, fontface=3) +
    annotate("text", x = 2, y=11.05146, label = "11.05", vjust =
    		 2.25, size=4, fontface=3) + 
    annotate("text", x = 3, y=11.15263, label = "11.15", vjust =
             2.25, size=4, fontface=3) +    
    	theme_bw() +
    	theme( 
    	axis.title.x=element_blank(),
    	axis.line = element_line(colour = "black"),
    	panel.grid.major = element_blank(), 
    	panel.grid.minor = element_blank(),
    	panel.border = element_blank(),
    	panel.background = element_blank()) +
    	theme(legend.position="None", legend.title=element_blank(), axis.text=element_text(size=12), legend.text=element_text(size=12), axis.title=element_text(size=12), legend.key.size = unit(1,"line")) 
 
D1<- D1 + scale_x_discrete(limits = c("prelockdown [50]","lockdown [50]\n(shortterm)", "postlockdown [50] \n(longterm)"))
D1<- D1 + labs(y="Gross Domestic Product (ln)")
 
 
#D1<- D1 + ggtitle(label = 'outcome: "number of daily events')

D1<- D1 + geom_point (x=1,y=11.0764, size = 1)
D1<- D1 + geom_point (x=2,y=11.05146, size = 1)
D1<- D1 + geom_point (x=3,y=11.15263, size = 1)


D1<- D1 + geom_segment(aes(x=1.00, y=11.07587, xend=1.00, yend=11.07693), linetype=1, data = data) +
    scale_color_manual(values = c("grey30", "grey30"))
D1<- D1 + geom_segment(aes(x=0.75, y=11.07587, xend=1.25, yend=11.07587), linetype=1, data = data)
D1<- D1 + geom_segment(aes(x=0.75, y=11.07693, xend=1.25, yend=11.07693), linetype=1, data = data)

D1<- D1 + geom_segment(aes(x=2.00, y=11.05067, xend=2.00, yend=11.05226), linetype=1, data = data)
D1<- D1 + geom_segment(aes(x=1.75, y=11.05067, xend=2.25, yend=11.05067), linetype=1, data = data)
D1<- D1 + geom_segment(aes(x=1.75, y=11.05226, xend=2.25, yend=11.05226), linetype=1, data = data)

D1<- D1 + geom_segment(aes(x=3.00, y=11.15168, xend=3.00, yend=11.15357), linetype=1, data = data) 
D1<- D1 + geom_segment(aes(x=2.75, y=11.15168, xend=3.25, yend=11.15168), linetype=1, data = data) 
D1<- D1 + geom_segment(aes(x=2.75, y=11.15357, xend=3.25, yend=11.15357), linetype=1, data = data)




D1<- D1 + geom_segment(aes(x=1.50, y=11.05, xend=1.50, yend=11.076), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=1.45, y=11.05, xend=1.55, yend=11.05), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=1.45, y=11.076, xend=1.55, yend=11.076), linetype="dotted", data = data) 


D1<- D1 + geom_point (x=1.50,y=11.06, size = 1)
D1<- D1 + geom_label(
    label="0.23%", 
    x=1.50,
    y=11.06,
    label.padding = unit(0.05, "lines"), # Rectangle size around label
    label.size = 0.15,
    color = "black",
    fill="#fff8dc"
  )


D1<- D1 + geom_segment(aes(x=2.50, y=11.08, xend=2.50, yend=11.15), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=2.45, y=11.08, xend=2.55, yend=11.08), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=2.45, y=11.15, xend=2.55, yend=11.15), linetype="dotted", data = data) 


D1<- D1 + geom_point (x=2.50,y=11.12, size = 1)
D1<- D1 + geom_label(
    label="0.69%", 
    x=2.50,
    y=11.12,
    label.padding = unit(0.05, "lines"), # Rectangle size around label
    label.size = 0.15,
    color = "black",
    fill="#fff8dc"
  )
print(D1)


#################################################################
#################  Figure 3b - Unemployment  ####################
#################################################################

data <- data.frame(
Q=c("prelock", "lock", "postlock"),
margins = c(7.050794, 7.8512, 6.414059),
cimin = c(7.041768, 7.837447, 6.398211),
cimax = c(7.05982, 7.864953, 6.429908)
) 

level_order <- c("prelock", "lock", "postlock")


D1 <- ggplot(data, aes(x = factor(Q, level = level_order), y=margins)) +
	scale_y_continuous(limits=c(6, 8))+
    annotate("text", x = 1, y=7.050794, label = "7.05", vjust =
             2.25, size=4, fontface=3) +
    annotate("text", x = 2, y=7.8512, label = "7.85", vjust =
    		 2.25, size=4, fontface=3) + 
    annotate("text", x = 3, y=6.414059, label = "6.41", vjust =
             2.25, size=4, fontface=3) +    
    	theme_bw() +
    	theme( 
    	axis.title.x=element_blank(),
    	axis.line = element_line(colour = "black"),
    	panel.grid.major = element_blank(), 
    	panel.grid.minor = element_blank(),
    	panel.border = element_blank(),
    	panel.background = element_blank()) +
    	theme(legend.position="None", legend.title=element_blank(), axis.text=element_text(size=12), legend.text=element_text(size=12), axis.title=element_text(size=12), legend.key.size = unit(1,"line")) 
 
D1<- D1 + scale_x_discrete(limits = c("prelockdown [50]","lockdown [50]\n(shortterm)", "postlockdown [50] \n(longterm)"))
D1<- D1 + labs(y="Unemployment (%)")
 
#D1<- D1 + ggtitle(label = 'outcome: "number of daily events')

D1<- D1 + geom_point (x=1,y=7.050794, size = 1)
D1<- D1 + geom_point (x=2,y=7.8512, size = 1)
D1<- D1 + geom_point (x=3,y=6.414059, size = 1)


D1<- D1 + geom_segment(aes(x=1.00, y=7.041768, xend=1.25, yend=7.041768), linetype=1, data = data) +
    scale_color_manual(values = c("grey30", "grey30"))
D1<- D1 + geom_segment(aes(x=0.75, y=7.041768, xend=1.25, yend=7.041768), linetype=1, data = data)
D1<- D1 + geom_segment(aes(x=0.75, y=7.05982, xend=1.25, yend=7.05982), linetype=1, data = data)

D1<- D1 + geom_segment(aes(x=2.00, y=7.837447, xend=2.25, yend=7.837447), linetype=1, data = data)
D1<- D1 + geom_segment(aes(x=1.75, y=7.837447, xend=2.25, yend=7.837447), linetype=1, data = data)
D1<- D1 + geom_segment(aes(x=1.75, y=7.864953, xend=2.25, yend=7.864953), linetype=1, data = data)

D1<- D1 + geom_segment(aes(x=3.00, y=6.398211, xend=3.25, yend=6.398211), linetype=1, data = data) 
D1<- D1 + geom_segment(aes(x=2.75, y=6.398211, xend=3.25, yend=6.398211), linetype=1, data = data) 
D1<- D1 + geom_segment(aes(x=2.75, y=6.429908, xend=3.25, yend=6.429908), linetype=1, data = data)


D1<- D1 + geom_segment(aes(x=1.50, y=7.05, xend=1.50, yend=7.85), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=1.45, y=7.05, xend=1.55, yend=7.05), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=1.45, y=7.85, xend=1.55, yend=7.85), linetype="dotted", data = data) 


D1<- D1 + geom_point (x=1.50,y=7.50, size = 1)
D1<- D1 + geom_label(
    label="11.35%", 
    x=1.50,
    y=7.50,
    label.padding = unit(0.05, "lines"), # Rectangle size around label
    label.size = 0.15,
    color = "black",
    fill="#fff8dc"
  )


D1<- D1 + geom_segment(aes(x=2.50, y=6.41, xend=2.50, yend=7.05), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=2.45, y=6.41, xend=2.55, yend=6.41), linetype="dotted", data = data) 
D1<- D1 + geom_segment(aes(x=2.45, y=7.05, xend=2.55, yend=7.05), linetype="dotted", data = data) 


D1<- D1 + geom_point (x=2.50,y=6.8, size = 1)
D1<- D1 + geom_label(
    label="9.03%", 
    x=2.5,
    y=6.8,
    label.padding = unit(0.05, "lines"), # Rectangle size around label
    label.size = 0.15,
    color = "black",
    fill="#fff8dc"
  )
print(D1)



#######################################################################
#################  Figure 4 - Coefficient Plots  ######################
#######################################################################

*******************************
*******************************
** GDP COEFFICIENT PLOT (4a)**
*******************************
*******************************

## Model CP1
var.names1<- c("GDP\n(ln, qtr lag)")
est1 <- c(-.1887714) 
se1 <- c(.000727857)       

## Model CP2
var.names2<- c("lockdown\n (shortterm)", "lockdown\n (longterm)",  "GDP\n(ln, qtr lag)")
est2<- c(-.3300657, -.3991054, -.174973)
se2<- c(.0197276, 0.0271377, .00076782)


## Put model estimates into temporary data.frames:
model1Frame <- data.frame(Variable = var.names1,
                          coefficient = est1,
                          SE = se1,
                          Model = "Model 5")
model2Frame <- data.frame(Variable = var.names2,
                          coefficient = est2,
                          SE = se2,
                          Model = "Model 6")

# Combine these data.frames
allModelFrame <- data.frame(rbind(model1Frame, model2Frame))  # etc.

# Specify the width of your confidence intervals
#interval <- -qnorm((1-0.9)/2)  # 90% multiplier
interval <- -qnorm((1-0.95)/2)  # 95% multiplier

#Plot#
allModelFrame$Variable <- factor(allModelFrame$Variable,levels=c("lockdown\n (shortterm)", "lockdown\n (longterm)",  "GDP\n(ln, qtr lag)"))
levels (allModelFrame$Variable)<- gsub("X", "\n", levels(allModelFrame$Variable))

zp1 <- ggplot(allModelFrame, aes(colour = Model))
zp1 <- zp1 + geom_hline(yintercept = 0.01, lty = 2)

zp1 <- zp1 + geom_pointrange(aes(x = Variable, y = coefficient, ymin = coefficient - SE*interval, ymax = coefficient + SE*interval), lwd = 0.8, position = position_dodge(width = 1/2), shape = 21, fill = "WHITE") 

zp1 <- zp1 + scale_color_manual(values=c("black", "steelblue3", "steelblue3"))
#zp1 <- zp1 + coord_flip() 
zp1 <- zp1 + theme_bw() + theme(text=element_text(family="serif", angle=90, vjust=0.5, lineheight=.8))
zp1 <- zp1 + xlab("") # remove word- variable
zp1 <- zp1 + theme(axis.text=element_text(size=10))
zp1 <- zp1 + theme(legend.position=c(.20,.80), legend.title=element_blank(),legend.background = element_rect(fill = "WHITE"), legend.key.height = unit(.02, "cm"),   legend.key.width = unit(0.02,"cm")) # remove word-  model
zp1 <- zp1 + guides(color = guide_legend(nrow = 1))

zp1 <- zp1 + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) # remove the grids
print(zp1) 



#######################################################################
#################  Figure 4b - Coefficient Plots  ######################
#######################################################################

***********************************
***********************************
** UNEMPLOYMENT COEFFICIENT PLOT **
***********************************
***********************************

## Model CP1
var.names1<- c("unemployment\n(ln, qtr lag)")
est1 <- c(0.028454) 
se1 <- c(0.052787)       

## Model CP2
var.names2<- c("lockdown\n (shortterm)", "lockdown\n (longterm)",  "unemployment\n(ln, qtr lag)")
est2<- c(-.3153572, -0.7278182, 0.166104)
se2<- c(.0250056, .03439, 0.055424)


## Put model estimates into temporary data.frames:
model1Frame <- data.frame(Variable = var.names1,
                          coefficient = est1,
                          SE = se1,
                          Model = "Model 7")
model2Frame <- data.frame(Variable = var.names2,
                          coefficient = est2,
                          SE = se2,
                          Model = "Model 8")

# Combine these data.frames
allModelFrame <- data.frame(rbind(model1Frame, model2Frame))  # etc.

# Specify the width of your confidence intervals
#interval <- -qnorm((1-0.9)/2)  # 90% multiplier
interval <- -qnorm((1-0.95)/2)  # 95% multiplier

#Plot#
allModelFrame$Variable <- factor(allModelFrame$Variable,levels=c("lockdown\n (shortterm)", "lockdown\n (longterm)",  "unemployment\n(ln, qtr lag)"))
levels (allModelFrame$Variable)<- gsub("X", "\n", levels(allModelFrame$Variable))

zp1 <- ggplot(allModelFrame, aes(colour = Model))
zp1 <- zp1 + geom_hline(yintercept = 0.01, lty = 2)

zp1 <- zp1 + geom_pointrange(aes(x = Variable, y = coefficient, ymin = coefficient - SE*interval, ymax = coefficient + SE*interval), lwd = 0.8, position = position_dodge(width = 1/2), shape = 21, fill = "WHITE") 

zp1 <- zp1 + scale_color_manual(values=c("black", "steelblue3", "steelblue3"))
#zp1 <- zp1 + coord_flip() 
zp1 <- zp1 + theme_bw() + theme(text=element_text(family="serif", angle=90, vjust=0.5, lineheight=.8))
zp1 <- zp1 + xlab("") # remove word- variable
zp1 <- zp1 + theme(axis.text=element_text(size=10))
zp1 <- zp1 + theme(legend.position=c(.20,.85), legend.title=element_blank(),legend.background = element_rect(fill = "WHITE"), legend.key.height = unit(.75, "cm"),   legend.key.width = unit(0.25,"cm")) # remove word-  model
zp1 <- zp1 + guides(color = guide_legend(nrow = 1))

zp1 <- zp1 + theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) # remove the grids
print(zp1) 



######################################
## Figure 5 Population Interaction ##
######################################

popdensity <- c(0, 1, 2, 3, 4, 5, 6, 7)
#lockdown
vmargin <- c(.6287742, .5625744, .5033443, .4503502, .4029356, .3605129, .3225567, .2885967)
vuppr <- c(.6107061, .5432808,  .4779249, .4186707, .3660718, .3197008, .2789401,  .2431687)
vlow <- c(.6468424, .581868, .5287638, .4820298,  .4397994, .4013251, .3661733, .3340246)

#no lockdown
pmargin <- c(.7615611, .7257902, .6916994, .65921, .6282465,  .5987375, .5706145, .5438124)
puppr <- c(.74503783, .7095396,   .6750107, .641606, .6094582, .5786479, .5492069,  .5211322)
plow <- c(.7780844, .7420408, .7083882, .6768139,  .6470349, .6188271, .592022, .5664926)

emoV1 <- data.frame()

F2 <- ggplot() +
  geom_line(data = emoV1, aes(popdensity, vmargin), color = "black", size = 1) + 
  geom_line(data = emoV1, aes(popdensity, vuppr), linetype="dotted") + 
  geom_line(data = emoV1, aes(popdensity, vlow), linetype="dotted") + 
  geom_line(data = emoV1, aes(popdensity, pmargin), color="steelblue3", size = 1) + 
  geom_line(data = emoV1, aes(popdensity, puppr), linetype="dotted",  color="steelblue3") + 
  geom_line(data = emoV1, aes(popdensity, plow), linetype="dotted", color="steelblue3") + 
  annotate("text", x = 2.5, y=.5625744, label = "lockdown [50]", vjust =
             2.25, size=4, fontface=3) +
  annotate("text", x = 5.2, y=.65921, label = "no lockdown [50]", vjust =
             2.25, size=4, fontface=3) +
  annotate("text", x = 6.5, y=.800, label = "", vjust =
             2.25, size=4, fontface="plain") +
  annotate("text", x = 0, y=.7, label = "17%", vjust =
             2.25, size=4, fontface=3) +
  annotate("text", x = 7, y=.45, label = "47%", vjust =
             2.25, size=4, fontface=3) +	
  theme_bw()+
  theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
  scale_y_continuous(name="\n number of nonstate actor violent events \n in district (daily)", breaks=seq(0, 1, by=.1)) +
  scale_x_continuous(name="\n population density", breaks=seq(0, 7, by=1), labels=c("0", "1", "2", "3", "4", "5", "6", "7")) +
  theme(axis.text = element_text(size = 12))  

#the above is reduction/percent change from no lockdown to lockdown  
#percent difference (19)vs 62, not percent change
#.6287742 and .7615611 (19%), .2885967-.5438124 (61%)

F2<- F2 + geom_segment(aes(x=0.00, y=0.73, xend=0.00, yend=0.66), linetype="dotted", data = emoV1) 
F2<- F2 + geom_segment(aes(x=-0.05, y=0.73, xend=0.05, yend=0.73), linetype="dotted", data = emoV1) 
F2<- F2 + geom_segment(aes(x=-0.05, y=0.66, xend=0.05, yend=0.66), linetype="dotted", data = emoV1) 

#F2<- F2 + geom_point (x=0,y=0.75, size = 1)
#F2<- F2 + geom_label(
#    label="19%", 
#    x=0,
#    y=0.75,
#    label.padding = unit(0.05, "lines"), # Rectangle size around label
#    label.size = 0.15,
#    color = "black",
#    fill="#fff8dc"
#  )

F2<- F2 + geom_segment(aes(x=7, y=.35, xend=7, yend=.50), linetype="dotted", data = emoV1) 
F2<- F2 + geom_segment(aes(x=6.95, y=.35, xend=7.05, yend=.35), linetype="dotted", data = emoV1) 
F2<- F2 + geom_segment(aes(x=6.95, y=.50, xend=7.05, yend=.50), linetype="dotted", data = emoV1) 


#F2<- F2 + geom_point (x=7,y=0.35, size = 1)
#F2<- F2 + geom_label(
#    label="61%", 
#    x=7,
#    y=.5,
#    label.padding = unit(0.05, "lines"), # Rectangle size around label
#    label.size = 0.15,
#    color = "black",
#    fill="#fff8dc"
#  )
print(F2)
  